package com.hu.service;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;

/**
 * @author 00355760
 * @功能：
 * @版本： V1
 * @版权： 信息技术有限公司（http://www.mychery.com/）
 * @作者： 磐石战队开发组  00355760
 * @日期： 2024/12/19 19:34
 */
@Service
public class MyThreadService3 {

    private final Executor executor;

    public MyThreadService3(@Qualifier("myAsync") ThreadPoolTaskExecutor executor) {
        this.executor = executor;
    }

    public void executeAsyncTask(CountDownLatch latch) {
        CompletableFuture.runAsync(() -> {
            // 异步任务逻辑
            System.out.println("正在执行：" + Thread.currentThread().getName());
            latch.countDown();
        }, executor);
    }
}
